import ajax from "@/common/ajax";
import mock from "../mock/index";
import { MessageAPi, ResponseData, LoginApi, PowerApi, MenuInfoApi, UserListApi, ResponseUserInfo, VisitorApi, VisitorListApi, MenuResponse, MenuListResponse } from "@/types"

// const request = import.meta.env.REACT_APP_MOCK === "1" ? mock : ajax;
const request = ajax;

const getMenu = () => request.get("/sys/getMenu") as Promise<MenuResponse>;
const getMenuList = () => request.get("/sys/getMenuList") as Promise<MenuListResponse>;
const login = (data: any) => request.post("/sys/login", data) as Promise<LoginApi>;
const addMenu = (data: any) => request.post("/sys/addMenu", data) as Promise<ResponseData>;
const getPower = () => request.get("/sys/getPower") as Promise<PowerApi>;
const delMenu = (data: any) => request.post("/sys/delMenu", data) as Promise<ResponseData>;
const getMenuInfo = (data: any) => request.get("/sys/getMenuInfo", data) as Promise<MenuInfoApi>;
const editMenu = (data: any) => request.post("/sys/editMenuInfo", data) as Promise<ResponseData>;
const getUserList = (data: any) => request.get("/sys/getUserList", data) as Promise<UserListApi>;
const addUser = (data: any) => request.post("/sys/addUserInfo", data) as Promise<ResponseData>;
const getUser = (data: any) => request.get("/sys/getUserInfo", data) as Promise<ResponseData & { data: ResponseUserInfo }>;
const editUser = (data: any) => request.post("/sys/editUserInfo", data) as Promise<ResponseData>;
const editType = (data: any) => request.post("/sys/editType", data) as Promise<ResponseData>;
const addType = (data: any) => request.post("/sys/addType", data) as Promise<ResponseData>;
const getVisitorList = (data: any) => request.get("/getiplist", data) as Promise<VisitorListApi>;
const getVisitorData = () => request.get("/getvisitordata") as Promise<VisitorApi>;
const addMsg = (data: any) => request.post("/addmessage", data) as Promise<ResponseData>;
const getMsg = (data: any) => request.get("/getmessage", data) as Promise<ResponseData>;
const getOrderList = (data: any) => request.post("/order/page", data);
const handleUpdate = (data: any) => request.post("/order/save", data);

const getOrderDetail = (data: any) => request.get(`/order/detail/${data}`,undefined);

// 字典查询
const dictType = (data: any) => request.post("/dict/list", data);
// 字典编辑
const saveType = (data: any) => request.post("/dict/save", data);
// 字典删除
const deleteType = (data: any) => request.post("/dict/delete", data);
// 生产过程信息表编辑
const processSave = (data: any) => request.post("/product/process/save", data);

// 返修信息表编辑
const repairSave = (data: any) => request.post("/repair/save", data);
// 生成二维码
// /back/order/getQrcode/{orderNumber}
const createQrCode = (data: any) => request.get(`/order/getQrcodePreview/${data}`, undefined);
// 删除
const orderRemove = (data: any) => request.delete(`/order/remove/${data}`, undefined);
// 批量结单
const orderDone = (data: any) => request.post("/order/orderDone", data);
// 人员新增
const employeeUserSave = (data: any) => request.post("/employeeUser/save", data);
// 人员列表
const employeeUserList = (data: any) => request.post("/employeeUser/page", data);
// 所有 /back/employeeUser/list
const employeeUserListAll = (data: any) => request.get("/employeeUser/list", data); 
// 删除人员
const employeeUserRemove = (data: any) => request.delete(`/employeeUser/remove/${data}`, undefined);
// 更新物流信息
const logisticsSave = (data: any) => request.post("/logistics/save", data);
// 导出
// /back/order/excelExport
const excelExport = (data: any) => request.post("/order/excelExport", data);
// 二维码 /back/order/getQrcode/{orderNumber}

// 批量获取二维码 /back/order/getQrcode/urlList
const getQrcodeList = (data: any) => request.post("/order/getQrcode/urlList", data);

// 修复二维码 /back/order/fix-qrcode
const fixQrcode = () => request.post("/order/fix-qrcode", null);
// 批量排产  /back/order/gen-product-time
const genProductTime = (data: any) => request.post("/order/gen-product-time", data);
// 导入 /back/order/excel-import
const excelImport = (data: any) => request.post("/order/excel-import", data);
// 导入模板下载 /back/order/excel-template
const excelTemplate = () => request.get("/order/excel-template");
// 获取省市区列表 /back/dict/province-list
const provinceList = (data: any) => request.post(`/dict/province-list`,data);


export const getFeedBack = (data: any) => request.post("/getfeedback", data) as Promise<ResponseData>;
export const reply = (data: any) => request.post("/reply", data) as Promise<ResponseData>;
export {
  getMenu,
  login,
  addMenu,
  addMsg,
  getMsg,
  getPower,
  delMenu,
  getMenuInfo,
  editMenu,
  getVisitorList,
  getVisitorData,
  getUserList,
  addUser,  
  getUser,
  editUser,
  editType,
  addType,
  getMenuList,
  getOrderList,
  handleUpdate,
  dictType,
  saveType,
  deleteType,
  getOrderDetail,
  processSave,
  repairSave,
  createQrCode,
  orderRemove,
  orderDone,
  employeeUserSave,
  employeeUserList,
  employeeUserRemove,
  logisticsSave,
  excelExport,
  employeeUserListAll,
  getQrcodeList,
  fixQrcode,
  genProductTime,
  excelTemplate,
  excelImport,
  provinceList
};
